package modellayer;

import java.util.ArrayList;


/**
 * The class OrderContainer is to collect objects of the class Order.
 * The pattern used here is called a Singleton Pattern. A Singleton
 * Pattern are used for saving objects you wanna use different places
 * in your system. The patterns makes sure that only one object of the
 * pattern is createt, and this object can be requested everywere.
 * 
 * @author Allan Eriksen, Christian Stidsborg, Andreas Rye, Casper Madsen, Stefan Bols 
 * @version 051213
 */
public class OrderContainer
{
    private static OrderContainer instance;
    private ArrayList<Order> orderList;

    /**
     * This constructor is private, so we are sure that only one object
     * of the class are created.
     */
    private OrderContainer()
    {
        orderList = new ArrayList<Order>();
    }
    
    /**
     * This method, getInstance, checks if the instance field are set
     * or not. If not (if null) - a new object of the class it self are initalized.
     * And then returned.
     * 
     * @return OrderContainer The OrderContainer object with Singleton Pattern.
     */
    public static OrderContainer getInstance()
    {
        if (instance==null) {
            instance = new OrderContainer();
        }
        
        return instance;
    }
    
    /**
     * This method adds a Order to the OrderContainer (collection of orders).
     * 
     * @param Order The Order there has to be added.
     */
    public void addOrder(Order order)
    {
        orderList.add(order);
    }
    
    public ArrayList<Order> getOrderList() {
    	return orderList;
    }
}
